package com.zch.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.item.service.MessageService;
import com.item.util.QueryParams;
import com.zch.dao.ChatMsgMapper;
import com.zch.dao.model.ChatMsg;
import com.zch.dao.model.ChatMsgExample;
import com.zch.daoEx.ChatMsgMapperEx;
import com.zch.daoEx.model.ChatMsgEx;

@Service
public class ChatMsgService {
	@Autowired
	private ChatMsgMapper chatMsgMapper;
	@Autowired
	private ChatMsgMapperEx chatMsgMapperEx;
	@Autowired
	private MessageService messageService;

	public int countByExample(ChatMsgExample example) {
		return this.chatMsgMapper.countByExample(example);
	}

	public ChatMsg selectByPrimaryKey(String id) {
		return this.chatMsgMapper.selectByPrimaryKey(id);
	}

	public List<ChatMsg> selectByExample(ChatMsgExample example) {
		return this.chatMsgMapper.selectByExample(example);
	}

	public int deleteByPrimaryKey(String id) {
		return this.chatMsgMapper.deleteByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(ChatMsg record) {
		return this.chatMsgMapper.updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(ChatMsg record) {
		return this.chatMsgMapper.updateByPrimaryKey(record);
	}

	public int deleteByExample(ChatMsgExample example) {
		return this.chatMsgMapper.deleteByExample(example);
	}

	public int updateByExampleSelective(ChatMsg record, ChatMsgExample example) {
		return this.chatMsgMapper.updateByExampleSelective(record, example);
	}

	public int updateByExample(ChatMsg record, ChatMsgExample example) {
		return this.chatMsgMapper.updateByExample(record, example);
	}

	public int insert(ChatMsg record) {
		return this.chatMsgMapper.insert(record);
	}

	public int insertSelective(ChatMsg record) {
		return this.chatMsgMapper.insertSelective(record);
	}

	public List<ChatMsgEx> selectMsgList(QueryParams.Builder builder){
		return this.chatMsgMapperEx.selectMsgList(builder);
	}
	
	public List<String> selectUserList(String id){
		return this.chatMsgMapperEx.selectUserList(id);
	}
	
	public int deleteByUser(String userId){
		//删除相关消息记录
		ChatMsgExample example = new ChatMsgExample();
		example.or().andViewIdEqualTo(userId);
		int cnt = this.chatMsgMapper.deleteByExample(example);
		//删除相关通知
		messageService.deleteByUser(userId);
		return cnt;
	}
}
